Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use native DOMParser and XMLSerializer #26

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

nodaguti
Copy link

After #25, I've made a further progress in the direction of removing xml-js, migrating from a xml library that provides their original interface, to Web standard DOMParser and XMLSerializer.

With this change the package size with required dependencies will be reduced by ~128KB.

While DOMParser and XMLSerializer are supported since Chrome 4, for environments that don't support DOMParser and/or XMLSerializer, there are polyfills like xmldom and jsdom. xmldom is a lightweight (30KB) pure JS implementation of DOMParser and XMLSerializer with no dependencies on Node.js standard modules, so I use it in the updated tests to verify that our vast/vmap parsers will work well with xmldom.

Copy link
Owner

@ygoto3 ygoto3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some changes of yours can violate VMAP / VAST's schemas

const newAdBreak = new AdBreak(
adBreak._attributes.timeOffset,
adBreak._attributes.breakType,
adBreak.getAttribute('timeOffset') || '',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

timeOffset from VMAP 1.0 Schema is required and cannot be ''.

adBreak._attributes.timeOffset,
adBreak._attributes.breakType,
adBreak.getAttribute('timeOffset') || '',
adBreak.getAttribute('breakType') || '',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

breakType from VMAP 1.0 Schema is required.

adSources,
adBreak._attributes.breakId,
adBreak._attributes.repeatAfter,
adBreak.getAttribute('breakId') || '',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

breakId should be optional, but should not be an empty string.

minBitrate,
maxBitrate,
url || '',
delivery || '',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delivery from VAST 4.x is required and must be either "progressive" or "streaming"

maxBitrate,
url || '',
delivery || '',
type || '',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type from VAST 4.x is required and should not be an empty string

type || '',
width ? parseInt(width) : 0,
height ? parseInt(height) : 0,
codec || '',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codec from VAST 4.x takes values as specified by RFC
4281: http://tools.ietf.org/html/rfc4281

width ? parseInt(width) : 0,
height ? parseInt(height) : 0,
codec || '',
id || '',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id should not be an empty string

const trackingEvents = mapArrayOrElem(trackingNodes, tracking => {
if (tracking.parentNode?.nodeName.toLowerCase() !== 'trackingevents') return null;

const event = tracking.getAttribute('event') || '';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

event should not be an empty string

});
const inLine = new InLine('', '', impressions, creatives, void 0, void 0, void 0, void 0, void 0, errors, extensions);
const newAd = new Ad(ad._attributes?.id, ad._attributes?.sequence ? parseInt(ad._attributes.sequence) : void 0, inLine);
const adId = ad.getAttribute('id') || '';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id should not be an empty string

return newAd;
});
const newVast = new VAST(vastObj._attributes.version, ads);
const newVast = new VAST(vastRoot.getAttribute('version') || '', ads);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version should not be an empty string

@ygoto3
Copy link
Owner

ygoto3 commented Oct 7, 2024

Thank you for the pull request. I will pick this request over #25 after the review is done since the main use case of OMAP is assumed to run it on a Web browser for now, and the request is to optimize performance in that.
(However, the initial purpose of avoiding Web API was to make OMAP work universally by default, so we would take a different approach in the future)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants